import instance from '@/utils/axios';

export const getCategoryListAPI = (data: ReqCategoryList) => {
  return instance.get('/admin/category/list', { params: data });
};

export interface ReqCategoryList {
  page: number;
  page_size: number;
  pid: number | null;
  name: string;
}

export const addCategoryAPI = (data: { pid: number | null; name: string }) => {
  return instance.post('/admin/category/add', data);
};

export const deteleCategoryAPI = (id: number) => {
  return instance.post('/admin/category/del', { id });
};

export const editCategoryAPI = (data: { id: number | null; name: string }) => {
  return instance.post('/admin/category/edit', data);
};

export const detailsCategoryAPI = (id: number) => {
  return instance(`/admin/category/detail?id=${id}`);
};

// 商品列表
export const getGoodsListAPI = (data: ReqGoodsList) => {
  return instance('/admin/goods/list', { params: data });
};

export interface ReqGoodsList {
  page: number;
  page_size: number;
  cat_id: number | null;
  name: string;
}

// 商品新增
export const addGoodsAPI = (data: AddGoods) => {
  return instance.post('/admin/goods/add', data);
};

export interface AddGoods {
  cat_id: number | null;
  name: string;
  img: File[];
  price: number | null;
  remark: string;
}

// 商品详情
export const detailsGoodsInfoAPI = (id: number) => {
  return instance.get(`/admin/goods/detail?id=${id}`);
};

// 编辑商品
export const editGoodsInfoAPI = (data: FormData) => {
  return instance.post('/admin/goods/edit', data);
};

// 删除商品
export const delGoodAPI = (id: number) => {
  return instance.post('/admin/goods/del', { id });
};

// 商品分类的下拉列表
export interface CategorySelectList {
  page: number;
  page_size: number;
  pid: number | null;
  name: string;
}
export const categorySelectListAPI = (data: CategorySelectList) => {
  return instance.get('/admin/category/select_list', { params: data });
};
